package com.example.arithmeticleetcode.learnArithmetic;

import com.example.arithmeticleetcode.learnArithmetic.exercise.CircleLinkedListExercise;
import com.example.arithmeticleetcode.util.MyAssert;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-08-11 15:31
 **/
public class LinkeListTest {

    public static void testList(List<Integer> list) {
        list.add(11);
        list.add(22);
        list.add(33);
        list.add(44);

        list.add(0, 55); // {55, 11, 22, 33, 44}
        list.add(2, 66);// {55, 11, 66, 22, 33, 44}
        list.add(list.size(), 77); // {55, 11, 66, 22, 33, 44, 77}

        list.remove(0); // {11, 66, 22, 33, 44, 77}
        list.remove(2); // {11, 66, 33, 44, 77}
        list.remove(list.size() - 1); // {11, 66, 33, 44}

        MyAssert.test(list.indexOf(44) == 3);
        MyAssert.test(list.indexOf(22) == List.ELEMENT_NO_FUND);
        MyAssert.test(list.contains(33));
        MyAssert.test(list.get(0) == 11);
        MyAssert.test(list.get(1) == 66);
        MyAssert.test(list.get(list.size() - 1) == 44);

        System.out.println(list);
    }

    public static void josephus() {
        CircleLinkedListExercise<Integer> listExercise = new CircleLinkedListExercise<>();
        for (int i = 1; i <= 8; i ++) {
            listExercise.add(i);
        }

        System.out.println(listExercise);
        listExercise.reset();
        while (!listExercise.isEmpty()) {
            listExercise.next();
            listExercise.next();
            System.out.println(listExercise.remove());
        }
    }

    public static void main(String[] args) {

        josephus();
//        testList(new ArrayList<>());
//
//        testList(new LinkedList<>());

//        testList(new SingleLinkedList<>());

        testList(new CycleLinkedList<>());

        if (false) {
            System.out.println("11111");
        } else if (true){
            System.out.println("22222");
        }


//        List<Integer> list = new SingleLinkedList<>();
//        list.add(20);
//        list.add(0, 10);
//        list.add(30);
//        list.add(list.size(), 40);
//
//        System.out.println(list);
//        list.remove(1);
//        System.out.println(list);
//
//        List<Integer> list2 = new SingleLinkedList2<>();
//        list2.add(20);
//        list2.add(0, 10);
//        list2.add(30);
//        list2.add(list.size(), 40);
//
//        System.out.println(list2);
//        list2.remove(1);
//        System.out.println(list2);
    }
}
